package com.qianbei.common.init;

import android.text.TextUtils;

import com.qianbei.common.base.BaseApplication;

public class SetData {

    public static final String USER = "USER";                    //账号
    public static final String PSW = "PSW";                    //密码
    public static final String JOBID = "JOBID";                    //性别
    public static final String USER_NAME = "UserName";            //真实姓名
    public static final String NICK_NAME_KEY = "nickname";        //呢称
    public static final String COUNTRY_KEY = "country";            //国家
    public static final String CITY_KEY = "city";                //城市
    public static final String TYPE_KEY = "type";            //用户类型
    public static final String CAREER_KEY = "career";            //职业
    public static final String INTRODUCTION_KEY = "introduction"; //简介

    public static final String ANSWER_OPEN_KEY = "answer_open"; //问答是否开启
    public static final String WEIXIN_BIND_KEY = "weixin_bind";    //是否绑定微信
    public static final String FIRST_LOGIN_KEY = "first_login"; //首次登录
    private static boolean moreThan90 = false; //绑定银行卡
    public static final String BANK_CARD_FIRST_KEY = "bank_card_first"; //绑定银行卡是
    public static final String ANSWER_CONTENT_KEY = "answer_content"; //前辈回答内容草稿

    public static final String SET_WEN_DA_FIRST = "set_wen_da_first"; //记录问答第一次是否开启
    public static final String SET_BIND_WE_CHAT_FIRST = "set_bind_we_chat_first"; //记录第一次是否显示绑定微信dialog
    public static final String SET_WEN_DA_KAI_TONG = "wen_da_kai_tong"; //问答是否开通过

    public static final String LAST_VIEW_ID = "last_view_id";
    public static final String HEAD_IMG = "head_img";//头像

    public static final String JOBS = "JOBS";//取时时获得的派车单
    public static final String BUSINESS_TYPE = "business_type";
    public static final String ROUTE_NO = "route_no";
    public static final String VEHICLE_TOTAL_KM = "vehicle_total_km";

    public static final String LOAD_NULL_BOX = "load_null_box";
    public static final String LOAD_BOX_UNINSTALL = "load_box_uninstall";
    public static final String LOAD_BOX_INSTALL = "load_box_install";
    public static final String LOAD_FULL_BOX = "load_full_box";
    public static final String Android = "Android";
    public static final String clientType = "clientType";
    private static String TOKEN = "";

    public static String getToken() {
        return TOKEN;
    }

    public static void setToken(String token) {
        TOKEN = token;
    }

    public static String getUSER() {
        return getSp(USER);
    }

    public static void setUSER(String user) {
        setSp(USER, user);
    }

    public static String getPSW() {
        return getSp(PSW);
    }

    public static void setPSW(String psw) {
        setSp(PSW, psw);
    }

    public static void setNullBoxWeight(int weight) {
        setSp(LOAD_NULL_BOX, weight);
    }

    public static int getNullBoxWeight() {
        return getSp(LOAD_NULL_BOX, 0);
    }

    public static void setBoxUnInstallWeight(float weight) {
        setSp(LOAD_BOX_UNINSTALL, weight);
    }

    public static float getBoxUnInstallWeight() {
        return getSp(LOAD_BOX_UNINSTALL, 0f);
    }

    public static void setBoxInstallWeight(float weight) {
        setSp(LOAD_BOX_INSTALL, weight);
    }

    public static float getBoxInstallWeight() {
        return getSp(LOAD_BOX_INSTALL, 0f);
    }

    public static void setFullBoxWeight(int weight) {
        setSp(LOAD_FULL_BOX, weight);
    }

    public static int getFullBoxWeight() {
        return getSp(LOAD_FULL_BOX, 0);
    }

    private static void setSp(String key, float value) {
        BaseApplication.mApplication.getSharedPreferences("jiemian", 0).edit()
                .putFloat(key, value).apply();
    }

    private static float getSp(String key, float defaultValue) {
        return BaseApplication.mApplication.getSharedPreferences("jiemian", 0)
                .getFloat(key, defaultValue);
    }

    public static void setHeadImg(String headImg) {
        setSp(HEAD_IMG, headImg);
    }

    public static String getHeadImg() {
        return getSp(HEAD_IMG);
    }

    /**
     * 发现tab页 设置最后问答id
     *
     * @param lastViewId
     */
    public static void setLastViewId(String lastViewId) {
        setSp(LAST_VIEW_ID, lastViewId);
    }

    /**
     * 发现tab页 获取最后问答id
     *
     * @return
     */
    public static String getLastViewId() {
        return getSp(LAST_VIEW_ID);
    }


    /**
     * 密码
     *
     * @param isOpen
     */
    public static void setPass(String isOpen) {
        setSp(FIRST_LOGIN_KEY, isOpen);
    }

    public static String getPass() {
        return getSp(FIRST_LOGIN_KEY);
    }

    /**
     * 是否开启问答
     *
     * @param isOpen
     */
    public static void setAnswerOpen(boolean isOpen) {
        setSp(ANSWER_OPEN_KEY, isOpen);
    }

    public static boolean getAnswerOpen() {
        return getSp(ANSWER_OPEN_KEY, false);
    }

    /**
     * 是否回到过 问题
     *
     * @param idflag
     * @param isAnswer
     */
    public static void setAnswerQues(String idflag, boolean isAnswer) {
        setSp(idflag, isAnswer);
    }

    public static boolean getAnswerQues(String idflag) {
        return getSp(idflag, false);
    }

    /**
     * 是否绑定微信
     */

    public static void setBindWinXin(boolean isBind) {
        setSp(WEIXIN_BIND_KEY, isBind);
    }

    public static boolean getBindWeiXin() {
        return getSp(WEIXIN_BIND_KEY, false);
    }

    /**
     * 用户简介
     *
     * @param introduction
     */
    public static void setIntroduction(String introduction) {
        setSp(INTRODUCTION_KEY, introduction);
    }

    public static String getIntroduction() {
        return getSp(INTRODUCTION_KEY);
    }

    /**
     * 职业
     *
     * @param career
     */
    public static void setCareer(String career) {
        setSp(CAREER_KEY, career);
    }

    public static String getCareer() {
        return getSp(CAREER_KEY);
    }

    /**
     * 用户类型 1 前辈  0 晚辈
     *
     * @param type
     */
    public static void setUserType(String type) {
        setSp(TYPE_KEY, type);
    }

    public static String getUserType() {
        return getSp(TYPE_KEY);
    }

    /**
     * 呢称
     *
     * @param nickName
     */
    public static void setNickName(String nickName) {
        setSp(NICK_NAME_KEY, nickName);
    }

    public static String getNickName() {
        return getSp(NICK_NAME_KEY);
    }


    /**
     * 国家
     *
     * @param country
     */
    public static void setCountry(String country) {
        setSp(COUNTRY_KEY, country);
    }

    public static String getCountry() {
        return getSp(COUNTRY_KEY);
    }

    /**
     * 城市
     *
     * @param city
     */
    public static void setCity(String city) {
        setSp(CITY_KEY, city);
    }

    public static String getCity() {
        return getSp(CITY_KEY);
    }

    /**
     * Jobid
     *
     * @param sex
     */
    public static void setJobid(String sex) {
        setSp(JOBID, sex);
    }

    public static String getJobid() {
        return getSp(JOBID);
    }

    /**
     * jobJson
     *
     * @param businessType
     */
    public static void setBusinessType(int businessType) {
        setSp(BUSINESS_TYPE, businessType);
    }

    /**
     * 得到 -1 时请在业务代码时处理  1：医废  2：医塑   3：固废
     *
     * @return
     */
    public static int getBusinessType() {
        return getSp(BUSINESS_TYPE, -1);
    }

    /**
     * jobJson
     *
     * @param routeNo
     */
    public static void setRouteNo(String routeNo) {
        setSp(ROUTE_NO, routeNo);
    }

    /**
     * @return
     */
    public static String getRouteNo() {
        return getSp(ROUTE_NO);
    }

    /**
     * jobJson
     *
     * @param jobJson
     */
    public static void setJobs(String jobJson) {
        setSp(JOBS, jobJson);
    }

    public static String getJobs() {
        return getSp(JOBS);
    }

    /**
     * 保存牌号码
     *
     * @param content
     */
    public static void setCarid(String content) {
        setSp(ANSWER_CONTENT_KEY, content);
    }

    public static String getCarId() {
        return getSp(ANSWER_CONTENT_KEY);
    }

    public static void setVehicleTotalKm(String content) {
        setSp(VEHICLE_TOTAL_KM, content);
    }

    public static String getVehicleTotalKm() {
        return getSp(VEHICLE_TOTAL_KM);
    }

    public static String getFirstTag() {
        return getSp("first_tag");
    }

    public static void setFirstTag(String hxID) {
        setSp("first_tag", hxID);
    }


    public static String getUserName() {

        return getSp(USER_NAME);
    }

    public static void setUserName(String hxID) {
        GlobalConfig.getInstance().userName = hxID;
        setSp(USER_NAME, hxID);
    }

    public static String getFace() {

        return getSp("iconURl");
    }

    public static void setFace(String hxID) {
        GlobalConfig.getInstance().iconURl = hxID;
        setSp("iconURl", hxID);
    }

    public static String gethxID() {

        return getSp("hxID");
    }

    public static void sethxID(String hxID) {
        GlobalConfig.getInstance().hxID = hxID;
        setSp("hxID", hxID);
    }

    public static String getUserID() {
        return getSp("userID");
    }

    /**
     * 保存 用户身份
     *
     * @param userID
     */
    public static void setIdentity(String userID) {
        if (!TextUtils.isEmpty(userID)) {
            GlobalConfig.getInstance().userID = userID;
            setSp("getIdentity", userID);
        }
    }

    public static String getIdentity() {
        return getSp("getIdentity");
    }

    public static void setUserID(String userID) {
        GlobalConfig.getInstance().userID = userID;
        setSp("userID", userID);
    }

    /**
     * 用户电话 保存
     */
    public static String getUserPhone() {
        return getSp("userPhone");
    }

    public static void setUserPhone(String userPhone) {
        setSp("userPhone", userPhone);
    }


    public static String getUserRole() {
        return getSp("Role");
    }

    public static void setUserRole(String userPhone) {
        setSp("Role", userPhone);
    }

    private static String getSp(String key) {
        return BaseApplication.mApplication.getSharedPreferences("jiemian", 0)
                .getString(key, "");
    }

    private static void setSp(String key, String value) {
        BaseApplication.mApplication.getSharedPreferences("jiemian", 0).edit()
                .putString(key, value).commit();
    }

    private static void setSp(String key, boolean value) {
        BaseApplication.mApplication.getSharedPreferences("jiemian", 0).edit()
                .putBoolean(key, value).commit();
    }


    private static boolean getSp(String key, boolean defaultValue) {
        return BaseApplication.mApplication.getSharedPreferences("jiemian", 0)
                .getBoolean(key, defaultValue);
    }

    private static void setSp(String key, int value) {
        BaseApplication.mApplication.getSharedPreferences("jiemian", 0).edit()
                .putInt(key, value).commit();
    }

    private static int getSp(String key, int defaultValue) {
        return BaseApplication.mApplication.getSharedPreferences("jiemian", 0)
                .getInt(key, defaultValue);
    }

    /**
     * 获取聊天对象的 用户名
     *
     * @return
     */
    public static String getTouUsername(String id) {

        return getSp(id + "name");
    }

    /**
     * 获取聊天对象的用户名
     *
     * @param hxID
     */
    public static void setTouserName(String id, String hxID) {
        if (!TextUtils.isEmpty(hxID)) {
            setSp(id + "name", hxID);
        }
    }

    /**
     * 获取聊天对象的 用户头像
     *
     * @return
     */
    public static String getTouUseFace(String id) {

        return getSp(id + "face");
    }

    /**
     * 获取聊天对象的用户头像
     *
     * @param hxID
     */
    public static void setTouserFace(String id, String hxID) {
        if (!TextUtils.isEmpty(hxID)) {
            setSp(id + "face", hxID);
        }
    }

    /**
     * 保持环形密码
     */
    public static void sethxpass(String random_string) {
        setSp("random_string", random_string);
    }

    /**
     * 获取环形密码
     */
    public static String gethxpass() {
        return getSp("random_string");
    }

    /**
     * 设置是否 响铃
     */
    public static void setSound(boolean random_string) {
        BaseApplication.mApplication.getSharedPreferences("jiemian", 0).edit()
                .putBoolean("setSound", random_string).commit();
    }

    /**
     * 设置是否 响铃
     */
    public static boolean getSound() {

        return BaseApplication.mApplication.getSharedPreferences("jiemian", 0)
                .getBoolean("setSound", true);
    }

    /**
     * 设置是否 振动
     */
    public static void setVibrate(boolean random_string) {
        BaseApplication.mApplication.getSharedPreferences("jiemian", 0).edit()
                .putBoolean("setVibrate", random_string).commit();
    }

    /**
     * 设置是否 响铃
     */
    public static boolean getVibrate() {

        return BaseApplication.mApplication.getSharedPreferences("jiemian", 0)
                .getBoolean("setVibrate", true);
    }


    /**
     * 设置是显示说明
     */
    public static void setLoginshow(boolean random_string, String id) {
        BaseApplication.mApplication.getSharedPreferences("jiemian", 0).edit()
                .putBoolean(id, random_string).commit();
    }

    /**
     * 设置是否显示说明
     */
    public static boolean getLoginshow(String id) {

        return BaseApplication.mApplication.getSharedPreferences("jiemian", 0)
                .getBoolean(id, true);
    }

    public static void setApplyInfo(String info) {
        setSp("apply_info", info);
    }

    public static String getApplyInfo() {
        return getSp("apply_info");
    }


    /*是否显示 通话提示 按钮*/

    public static void setShowTipImage(String key, boolean flag) {
        setSp(key, flag);
    }

    public static boolean getShowTipImage(String key) {
        return getSp(key, false);
    }


    public static void setMoreThan90(boolean m) {
        moreThan90 = m;
    }

    public static boolean getMoreThan90() {
        return moreThan90;
    }
}
